/* ###################################################################
**     Filename    : main.c
**     Project     : Accel_y
**     Processor   : MKL25Z128VLK4
**     Version     : Driver 01.01
**     Compiler    : GNU C Compiler
**     Date/Time   : 2017-01-17, 09:02, # CodeGen: 0
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
**         Main module.
**         This module contains user's application code.
*/         
/*!
**  @addtogroup main_module main module documentation
**  @{
*/         
/* MODULE main */


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "AS1.h"
#include "CI2C1.h"
#include "GPIO1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "MMA8451Q.h"
#include"string.h"
#include"stdio.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
LDD_TDeviceData *Serial1;
LDD_TDeviceData *LED_R;
LDD_TDeviceData *I2C;
char OutData[12];
char InData[6];
unsigned char MMA8451_ID;
bool DataSendedFlg=0;
bool DataReceivedFlg=0;
bool DataRightFlg=1;
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  LED_R=GPIO1_Init(NULL);
  GPIO1_SetFieldValue(LED_R,led_r,0);
  Serial1=AS1_Init(NULL);
  I2C=CI2C1_Init(NULL);

  AS1_SendBlock(Serial1,"hello",5);

  MMA8451Q_Init();

  AS1_SendBlock(Serial1,"ID",2);
  AS1_SendBlock(Serial1,&MMA8451_ID,8);
  for(int i=100000;i>0;i--);

  GPIO1_SetFieldValue(LED_R,led_r,1);

  while(1)
  {
	  MMA8451Q_read();
	  for(int i=30000;i>0;i--);
	  if(DataRightFlg==1)
	  {
		  AS1_SendBlock(Serial1,InData,6);
	  }
	  else
	  {
		  DataRightFlg=1;
	  }
	  for(int i=30000;i>0;i--);


  }
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.5 [05.21]
**     for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
